package com.xxg.renrenorder.message;

import com.alibaba.fastjson.JSON;
import com.xxg.renrenorder.dao.bean.OrderMsg;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static com.xxg.renrenorder.config.RabbitMQConfig.*;


/**
 * 订单消息发送类
 *
 * @author xxg
 * @date 2020/12/29
 */
@Component
public class DelayMessageSender {
    private static final Logger logger = LoggerFactory.getLogger(DelayMessageSender.class);
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sendMsg(OrderMsg order) {
        String msg = JSON.toJSONString(order);
        logger.info("收到订单,进行30M倒计时，订单信息:" + msg);
        rabbitTemplate.convertAndSend(DELAY_EXCHANGE_NAME, DELAY_QUEUE_ROUTING_KEY, msg);
    }

    /**
     * 拼团支付成功后30分钟默认拼成功
     * @param order 订单信息
     */
    public void sendMsgGroupBuy(OrderMsg order) {
        String msg = JSON.toJSONString(order);
        logger.info("收到订单,进行30M倒计时，订单信息:" + msg);
        rabbitTemplate.convertAndSend(DELAY_EXCHANGE_NAME, DELAY_QUEUE_GROUP_BUY_ROUTING_KEY, msg);
    }

    /**
     * 订单发货开始计时10天自动收货
     *
     * @param order 订单信息
     */
    public void sendMsgA(OrderMsg order) {
        String msg = JSON.toJSONString(order);
        logger.info("收到订单,进行10天倒计时，订单信息:" + msg);
        rabbitTemplate.convertAndSend(DELAY_EXCHANGE_NAME, DELAY_QUEUEA_ROUTING_KEY, msg);
    }

    /**
     * 订单确认收货后开始计时15天自动关闭售后
     *
     * @param order 订单信息
     */
    public void sendMsgB(OrderMsg order) {
        String msg = JSON.toJSONString(order);
        logger.info("收到订单,进行15天倒计时，订单信息:" + msg);
        rabbitTemplate.convertAndSend(DELAY_EXCHANGE_NAME, DELAY_QUEUEB_ROUTING_KEY, msg);
    }

    /**
     * 订单发货后开始计时15天收益结算
     *
     * @param order 订单信息
     */
    public void sendMsgC(OrderMsg order) {
        String msg = JSON.toJSONString(order);
        logger.info("收到订单,进行30天倒计时，订单信息:" + msg);
        rabbitTemplate.convertAndSend(DELAY_EXCHANGE_NAME, DELAY_QUEUEC_ROUTING_KEY, msg);
    }
}
